#!/usr/bin/env python
# -*- coding: utf-8 -*-

# This project is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# 
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This project is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Tutoo Installer.  If not, see <http://www.gnu.org/licenses/>.

from distutils.core import setup,Extension
from distutils.command.install import install
from distutils.cmd import Command
from distutils.errors import *
import glob, os, sys

def getAllUis():
	files = []
	dirs = ['.',]
	print 'Searching for interfaces to compile',
	for dir in dirs:
		for file in os.listdir(dir):
			file = os.path.join(dir,file)
			if os.path.isdir(file):
				dirs.append(file)
			elif file.endswith('.ui'):
				files.append(file)
				print '.',
				sys.stdout.flush()
	if files:
		print '%d Interfaces found!' % len(files)
	else:
		print '\033[31;1m%s\033[m' % 'No interfaces found!'
	return files

def makeUiCompilation():
	for n, file in enumerate(getAllUis()):
		print '\033[33;1m%d\033[m %s' % (n+1,'Compiling user interface %s' % file)
		os.system('pyuic4 -i 0 -x -o %s %s' % (file.replace('.ui','.py'), file,))

class compileUi(Command):
	user_options = []
	def initialize_options(self):
		pass
	def finalize_options(self):
		pass
	def run(self):
		makeUiCompilation()

setup(name='Project mc723',
	version = '0.1',
	description = 'GUI to make a structure of processor and memory',
	author = 'Roberto Miura Honji',
	author_email = 'roberto@las.ic.unicamp.br',
	packages = [],
	py_modules = [],
	scripts = [],
	ext_modules = [],
	cmdclass = {'uicompile' : compileUi,},
	)
